from google.appengine.ext import db
from google.appengine.api.users import User

from apps.campaign.models import Campaign


class Group(db.Model):
    """A chat Group, analogus to a room in orpg1, but also a whisper group.
    a user can belong to unlimited number of groups for the campaign since
    there is no tie in with a map belonging to a specific group."""
    campaign = db.ReferenceProperty(Campaign, collection_name='groups')
    name = db.StringProperty(required=True)
    description = db.TextProperty()
    private = db.BooleanProperty(default=False)
    password == db.StringListProperty(indexed=False)
    permanent = db.BooleanProperty(default=False)
    moderated = db.BooleanProperty(default=True)
    players = db.ListProperty(User)
    voice = db.ListProperty(User)

    last_used = db.DateTimeProperty(auto_now=True)

class Message(db.Model):
    """A chat message that has been parsed & sanatized. It stores who sent it
    who it is to (if the message was sent to a group it is the views job to
    create a message for each user in the group."""
    sender = db.UserProperty(auto_current_user_add=True)
    to = db.UserProperty(User)
    type = db.StringProperty(choices=('normal', 'emote', 'ooc',
                                      'info', 'system', 'move'),
                             default='normal')
    alias = db.StringProperty(indexed=False)
    style = db.StringListProperty()
    message = db.TextProperty()

    sent = db.DateTimeProperty(auto_now_add=True, indexed=False)
    recived = db.BooleanProperty(default=False)

class Log(db.Model):
    """Named log of users recived messages. This is to make it easy for GMs
    to create a chat log. They start a log and name it, the system adds every
    message the user recives to that log, then the user can goto some url
    and selectivly remove messages and make it public."""
    owner = db.UserProperty(auto_current_user_add=True)
    name = db.StringProperty(required=True, indexed=True)
    messages = db.ListProperty(Message)
    active = db.BooleanProperty(default=True)
    public = db.BooleanProperty(default=False)

